<template>
	<view>
		<view class="main">
			<view class="box">
				<input class="input" @input="getphone" maxlength="11" type="number" placeholder="137****5226" placeholder-class="title_pla" />
				<!-- <view class="input"> {{phone}}</view> -->
				<view class="btn1" v-if="show" @click="getgoCode">发送验证码</view>
				<view class="btn1" v-if="!show">{{times}}s</view>
			</view>
			<view class="box">
				<input class="input" @input="getcode" maxlength="6" type="number" placeholder="请输入6位数短信验证码" placeholder-class="title_pla" />
			</view>
			<view class="box">
				<input class="input" @input="getpwd" maxlength="6" type="number" placeholder="请设置提现密码" placeholder-class="title_pla" />
			</view>
			<view class="box">
				<input class="input" @input="getagain" maxlength="6" type="number" placeholder="再次输入提现密码" placeholder-class="title_pla" />
			</view>
			<view class="box1">
				<view class="btn2" @click="editCashPwd">完成</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		changepwd,
		editCashPwd
	} from '@/api/user.js';
	export default {
		data() {
			return {
				show: true,
				times: 60,
				phone: '',
				code: '',
				pwd: '',
				again: '',
			}
		},
		onLoad() {
			let that = this;
		},
		methods: {
			getphone(){
				
			},
			getgoCode() {
				let that = this;
				let phone = that.phone;
				let isagree = that.isagree;
				that.times = 60;
				if (!/^1[34578]\d{9}$/.test(that.phone)) {
					wx.showToast({
						title: '请输入正确的11位手机号',
						icon: 'none'
					})
					return
				} else {

					this.show = false
					this.timer = setInterval(() => {
						this.times--
						if (this.times === 0) {
							this.show = true
							clearInterval(this.timer)
						}
					}, 1000)

					this.changepwd()
				}
			},

			editCashPwd: function(e) {
				let that = this;
				let data = {
					phone: that.phone,
					code: that.code,
					new_cashpwd: that.pwd,
					re_cashpwd: that.again,
				}
				data = JSON.stringify(data);
				console.log('data', data)

				editCashPwd(data).then(res => {
					console.log('返回值', res)
					setTimeout(function() {
						uni.showToast({
							title: res.data.msg,
							icon: "none",
							duration: 1000,
						})
					}, 1000);
					uni.navigateBack({
						delta: 1
					})

				}).catch(err => {
					return this.$util.Tips({
						title: err
					});
				});
			},
			changepwd: function(e) {
				let that = this;
				changepwd(that.phone).then(res => {
					console.log('返回值', res)
					uni.showToast({
						title: '发送成功',
						icon: 'none',
						duration: 1000,
					})

				}).catch(err => {
					return this.$util.Tips({
						title: err
					});
				});
			},

			getphone: function(event) {
				let that = this;
				that.phone = event.target.value
				console.log("that.phone", that.phone)
			},
			getcode: function(event) {
				let that = this;
				that.code = event.target.value
				console.log("that.code", that.code)
			},
			getpwd: function(event) {
				let that = this;
				that.pwd = event.target.value
				console.log("that.pwd", that.pwd)
			},
			getagain: function(event) {
				let that = this;
				that.again = event.target.value
				console.log("that.again", that.again)
			},
		}
	}
</script>

<style lang="scss">
	page {

		.main {

			width: 100%;
			height: 100vh;

			.box {
				border: 1rpx solid #EEEEEE;
				padding: 0 50rpx;
				width: 100%;
				height: 128rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.title_pla {

					font-size: 32rpx;

					font-weight: 500;
					text-align: left;
					color: #999999;

				}

				.input {
					font-size: 32rpx;

					font-weight: 500;
					text-align: left;
				}

				.btn1 {
					width: 136rpx;
					height: 48rpx;
					background: #d3af6b;
					font-size: 24rpx;
					font-weight: 500;
					text-align: center;
					color: #ffffff;
					line-height: 48rpx;
				}
			}

			.box1 {
				display: flex;
				justify-content: center;
				align-items: center;

				.btn2 {
					margin-top: 100rpx;
					width: 160rpx;
					height: 66rpx;
					background: #d3af6b;
					border-radius: 3rpx;

					font-size: 32rpx;

					font-weight: 500;
					text-align: center;
					color: #ffffff;
					line-height: 66rpx;
				}
			}
		}
	}
</style>
